//
//  CommunityHeaderView.m
//  Team
//
//  Created by lanou3g on 16/1/15.
//  Copyright © 2016年 ZJF. All rights reserved.
//

#import "CommunityHeaderView.h"
#import "GameTableViewController.h"

#define kWidth self.frame.size.width/4.0
#define kHeight self.frame.size.height/2.0

@implementation CommunityHeaderView


-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        NSArray *array1 = @[@"chengzhang",@"knowledge",@"food",@"jianshen",@"game",@"doctor",@"growth",@"news"];
        NSArray *array2 = @[@"宝宝里程碑",@"育儿知识",@"今日辅食",@"产后瘦身",@"亲子游戏",@"名医解读",@"时光轴",@"亲子资讯"];
        
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 4; j++) {
                UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(kWidth * j, kHeight * i, kWidth, kHeight)];
                aView.backgroundColor = [UIColor clearColor];
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkDetail:)];
                [aView addGestureRecognizer:tap];
                aView.tag = 1000+(4*i + j);
                
                UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:array1[4 * i + j]]];
                imgView.frame = CGRectMake(kWidth*3.0/8.0, kWidth/4.0, kWidth/4.0, kWidth/4.0);
                [aView addSubview:imgView];
                
                UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, kHeight/2.0, kWidth, kHeight/4.0)];
                titleLabel.backgroundColor = [UIColor clearColor];
                titleLabel.text = array2[4 * i + j];
                titleLabel.textAlignment = 1;
                [aView addSubview:titleLabel];
                
                [self addSubview:aView];
            }
        }
        
    }
    
    return self;
}





-(void)checkDetail:(UITapGestureRecognizer *)sender{
    
//    if (sender.view.tag == 1004) {
//        
//        [_delegate goTo:(1004)];
//        
//    }else if (sender.view.tag == 1007) {
//        
//        [_delegate goTo];
//    }
    
    [_delegate goTo:sender.view.tag];
    
}








/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


@end
